package com.glsc.ngateway.oaflow.service;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.TRPARequest;
import com.glsc.ngateway.common.base.repo.mysql.gateway.platform.TRPARequestRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
public class RPAService {

    private static final Logger logger = LoggerFactory.getLogger(RPAService.class);

    @Autowired
    TRPARequestRepository trpaRequestRepository;

    public List<String> getRequestList() {
        List<String> reqlist = new ArrayList<>();
        List<TRPARequest> list = trpaRequestRepository.findByStatus("0");
        for (TRPARequest l : list) {
            reqlist.add(l.getRequestId());
        }
        return reqlist;
    }

    @Transactional
    public void updateRequestStatus(List<String> requestList) {
        List<TRPARequest> list = trpaRequestRepository.findByRequestIdList(requestList);
        for (TRPARequest l : list) {
            l.setStatus("1");
            l.setUpdateTime(LocalDateTime.now());
            trpaRequestRepository.save(l);
        }
    }
}
